package com.example.testnt;

import android.app.NativeActivity;
import android.os.Handler;
import android.widget.Button;
import android.widget.TextView;

public class ServerTask extends AbstractEchoTask {

    private final int port;
    private EchoServerActivity echoServerActivity;

    protected ServerTask(Button startButton, TextView logView, int port
            , EchoServerActivity echoServerActivity) {

        super(startButton, logView);
        this.port = port;
        this.echoServerActivity = echoServerActivity;
    }

    @Override
    protected void onBackground() {

        echoServerActivity.logMessage("STARTING SERVER");
        try {

//            echoServerActivity.nativeStartTcpServer(port);
            //调用原生代码
            echoServerActivity.nativeStartUdpServer(port);
        } catch (Exception e) {
            echoServerActivity.logMessage(e.getMessage());
        }
        echoServerActivity.logMessage("SERVER TERMINATED");
    }
}
